﻿<%@ WebHandler Language="C#" Class="AjaxController" %>

using System;
using System.Web;
using DarkAjax.Utility;
using DarkCRM.Models;
public class AjaxController : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
    
    public void ProcessRequest (HttpContext context) {
        
        string className = context.Request["_class"];
        string _method = context.Request["_method"];
        Member member = DarkCRM.Models.Member.GetCookieAdmin();
        if (!className.Equals("member",StringComparison.OrdinalIgnoreCase) || !_method.Equals("login",StringComparison.OrdinalIgnoreCase) )
        {
            if (member.DisplayName.Length == 0)
            {
                
                context.Response.Write(new ResultMessage(){ErrorCode=9999,Description="没有登录,或登录信息异常"}.ToString());
                context.Response.End();    
            }

            bool canAllow = ControllerAction.CheckAllowToAction(member.MemberID, 0, className, _method);
            if (!canAllow)
            {                
                context.Response.Write(new ResultMessage(){ErrorCode=9999,Description="对不起，没有权限执行该方法"}.ToString());
                context.Response.End();
            }
        }

        
        switch (className.ToLower())
        {
            //case "admin":
            //    jQueryAjaxUtility.RegisterAjaxInvokeEvent(typeof(DarkCRM.Admin));
            //    break;
            //case "production":
            //    jQueryAjaxUtility.RegisterAjaxInvokeEvent(typeof(DarkCRM.Production));
            //    break;
            case "custom":
                jQueryAjaxUtility.RegisterAjaxInvokeEvent(typeof(DarkCRM.Models.Custom));
                break;
            case "member":
                jQueryAjaxUtility.RegisterAjaxInvokeEvent(typeof(DarkCRM.Models.Member));
                break;
            case "customfollowupstatus":
                jQueryAjaxUtility.RegisterAjaxInvokeEvent(typeof(DarkCRM.Models.CustomFollowupStatus));
                break;
            case "customfollowup":
                jQueryAjaxUtility.RegisterAjaxInvokeEvent(typeof(DarkCRM.Models.CustomFollowup));
                break;
            case "controlleraction":
                jQueryAjaxUtility.RegisterAjaxInvokeEvent(typeof(DarkCRM.Models.ControllerAction));
                break;
            default:
                break;
        }
        context.Response.Write(new ResultMessage() { ErrorCode = 9999, Description = "请提供_class" }.ToString());        
    }
 
    public bool IsReusable {
        get {
            return true;
        }
    }

}